package com.zoweunion.mechanic.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.service.NeedLeaseService;
import com.zoweunion.mechanic.entity.NeedLeaseEntity;


import com.zoweunion.mechanic.model.ResponseBean;
import com.github.pagehelper.PageInfo;

import javax.servlet.http.HttpServletRequest;


/**
 * @author xp
 * @email 17688825585@163.com
 * @date 2021-04-19 19:07:47
 */
@RestController
@RequestMapping("/needlease")
public class NeedLeaseController extends BaseController {
    @Autowired
    private NeedLeaseService needLeaseService;

    /**
     * 列表
     */
    @GetMapping("/needLeaseList")
    public ResponseBean needLeaseList(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = needLeaseService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增 
     */
    @PostMapping("/needLeaseInsertUpdate")
    public ResponseBean needLeaseInsertUpdate(@RequestBody NeedLeaseEntity params,
                                              HttpServletRequest request) throws MyException {
        String id = getCurrentUser(request).getId();
        if (params.getId() != null) {
            needLeaseService.updateById(params);
        } else {
            params.setCreateUser(id);
            params.setCreateTime(new Date());
            needLeaseService.save(params);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }


}
